import Tab from '../tab/tab.vue'
import Pages from '../../../pages/pages.vue'
import { showMsg, setMenuType, getMemberList, updateAdvisorUser, deleteMember } from '../../../../vuex/action'

export default {
  name: 'advisor-list',
  components: {
    'vue-tab': Tab,
    'vue-pages': Pages
  },
  data() {
    return {
      list: []
    }
  },
  computed: {
    playerId() {
      return this.$route.query.playerId
    }
  },
  vuex: {
    getters: {
      fresh: state => state.classesListNeedFresh
    },
    actions: {
      xShowMsg: showMsg,
      xSetMenuType: setMenuType,
      xUpdateAdvisor: updateAdvisorUser,
      xGetList: getMemberList,
      xDeleteAdvisor: deleteMember,
    }
  },
  ready() {
    this.xSetMenuType('activity')
    this.getList()
  },
  methods: {
    getList() {
      this.xGetList({
        playerId: this.playerId
      })
        .then((data) => {
          this.list = data.list
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    openPicPage(picUrl){
      window.open(picUrl)
    },
    updateCertificateNo(it){
      this.xUpdateAdvisor({
        id: it.id,
        certificateNo: it.certificateNo
      }).then(() =>{
        this.getList()
      })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    deleteItem(id){
      this.xDeleteAdvisor({
        id: id
      })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
  },
  watch: {
    fresh() {
      if (this.fresh) {
        this.getList()
      }
    }
  }
}
